package com.zjg.vue_cms.conf;

import com.zjg.vue_cms.interceptor.BaseInterceptor;
import com.zjg.vue_cms.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

/**
 * @author guass
 * @date 2022年04月16日 11:07
 */
@Configuration
public class CmsWebConf implements WebMvcConfigurer {



    @Resource
    private LoginInterceptor loginInterceptor;

    @Resource
    private BaseInterceptor baseInterceptor;



    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOriginPatterns("*")
                .allowCredentials(true)
                .allowedMethods("GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS", "ERROR")
                .maxAge(3600);
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        registry.addInterceptor(baseInterceptor).addPathPatterns("/**");

        registry.
                // 添加拦截器
                        addInterceptor(loginInterceptor).
                // 添加拦截路径
                        addPathPatterns("/login/**").
                // 白名单
                        excludePathPatterns("/login");


    }

}
